<?php echo $javascript->link('thickbox', false); ?>
<div class="profiles index profiles-all">
<h1><?php __('All Baker Profiles');?></h1>

<?php //debug($profiles)?>

<div class="wrap">
<?php echo $this->renderElement('mapjs'); ?>
<div id="message" style="display:none;"></div>
<div id="map"></div>

<script type="text/javascript">
	//<![CDATA[
	google.load("maps", "2.x");
	jQuery(document).ready(function() {
		
		
		//jQuery("#map").append("<strong>" + data[i]['Profile']['slug'] + "</strong>");
		
		if (GBrowserIsCompatible()) {
		var map = new GMap2(jQuery("#map").get(0));
		var data = <?php echo $javascript->Object($profiles) ?>;
		var zoom = <?php echo Configure::read('Map.zoom') ?>;
		//var markers = [];
		var point;
		var marker;
		var bounds = new GLatLngBounds();
		
		map.addControl(new GLargeMapControl());
		
		
		for (var i=0; i < data.length; i++) {
			point = new GLatLng(data[i]['Profile']['latitude'],data[i]['Profile']['longitude']);
			marker = new GMarker(point);
			map.addOverlay(marker);
			bounds.extend(marker.getPoint());
			//markers[i] = marker;
		}
		map.setCenter(point, zoom);
		map.setZoom(map.getBoundsZoomLevel(bounds));
		map.setCenter(bounds.getCenter());
		
		}
	});
	//]]>
</script>

<div class="sidebar">
	<cake:nocache>
	<?php if(isset($auth_user)):?>
		<?php foreach ($profiles as $profile): ?>
			<div class="baker">
				<div class="avetar">
					<?php echo $this->renderElement('../profiles/thumb', array("profile" => $profile, 'image_size' => 'minithumb')); ?>
				</div>
				<h3 class="title"><?php echo $html->link( $profile['Profile']['slug'], array('action'=>'view', $profile['Profile']['slug'])); ?></h3> 

			</div>
		<?php endforeach; ?>
	<?php else: ?>
		<?php echo Configure::read('Profile.sidebar')?>
		
		<p><?php echo $html->link(__('Join today', true), array('admin'=>false, 'plugin'=>'authake','controller'=>'user', 'action'=>'register'), array('class'=>'button-link')) ?></p>
	<?php endif; ?>
	</cake:nocache>
	

</div>
</div>

<?php if(isset($auth_user)) echo $this->element('paging'); ?>

</div>
